﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_editopcion : System.Web.UI.Page
{
    string idoption; string parent; int opcionid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                idoption = Request.QueryString["Id"].ToString();
                parent = Request.QueryString["parent"].ToString();
                if (idoption != null && parent != null)
                {
                    string sxml = crearxml();


                    com.bpophotos.www.Service service = new com.bpophotos.www.Service();
                    //referencia1.Service service = new referencia1.Service();
                    int par = int.Parse(parent);
                   string pagop = service.getAppOptions(par);
                   // string pagop = "";
                    DataSet pagopp = Utility.getPermitOption(pagop);
                    for (int i = 0; i <= pagopp.Tables[0].Rows.Count - 1; i++)
                    {

                        string nombre = pagopp.Tables[0].Rows[i]["name_option"].ToString();
                        opcionid = int.Parse(pagopp.Tables[0].Rows[i]["id_option"].ToString());
                        if (opcionid == int.Parse(idoption))
                        {
                            tb_role.Text = nombre;
                           
                        }
                    }

                }
                

            }
            catch (Exception ex)
            {
                Response.Redirect("application.aspx");
            }
        }
    }

    private string crearxml()
    {
        string result = "";
        idoption = Request.QueryString["Id"].ToString();
        parent = Request.QueryString["parent"].ToString();
        result += "<?xml version=\"1.0\" encoding=\"utf-8\"?><data><opcionid>" + idoption + "</opcionid><parent>"+parent+"</parent>";
        result += "<opcionname>" + tb_role.Text + "</opcionname>";
        result += "</data>";

        return result;
    }
   
    protected void lnk_save_Click(object sender, EventArgs e)
    {
        string sxml = crearxml();
        com.bpophotos.www.Service service = new com.bpophotos.www.Service();
        service.updateDataOption(sxml);
    }
    protected void lnk_delete_Click(object sender, EventArgs e)
    {
        idoption = Request.QueryString["Id"].ToString();
        parent = Request.QueryString["parent"].ToString();
        Response.Redirect("deleteOptionO.aspx?id=" + idoption + "&parent=" + parent);
    }
}